package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.CouponInfo;
import com.topscore.uke.mvp.contractors.GetCouponsInfoContractor;
import com.topscore.uke.mvp.model.GetCouponInfoModel;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.utils.UserInfoManager;

import java.util.List;

/**
 * Created by 71468 on 2018/3/28.
 */

public class GetCouponsInfoPresenter implements GetCouponsInfoContractor, GetCouponsInfoContractor.Presenter, GetCouponsInfoContractor.CallBack {
    private final String mLoginName;
    private View mView;
    private Model mModel;

    public GetCouponsInfoPresenter(View view) {
        this.mView = view;
        mLoginName = UserInfoManager.getUserInfo().getLoginName();
        mModel = new GetCouponInfoModel(this);
    }

    @Override
    public void getCoupons(String status) {
        mView.onLoading("");
        mModel.getCoupons(mLoginName,status);
    }

    @Override
    public void onError(int errorCode, String errorMessage) {
        mView.onFail(errorCode,errorMessage);
    }

    @Override
    public void onComplete() {
        mView.onLoadFinished();
    }

    @Override
    public void onGetDataSuccess(BaseResponse<List<CouponInfo>> response) {
        mView.onGetCouponDataSuccess(response.getData());
    }
}
